home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / program / ddj0897.zip / CCDBMS.ZIP / DATABASE.CPP next >
C/C++ Source or Header  |  1997-03-18  |  7KB  |  213 lines

  1. // =================================================================
  2. // Database.cpp
  3. // =================================================================
  4. // Harold Kasperink / John Dekker 
  5. // Dr. Dobb's Journal 1997
  6. // =================================================================
  7. // Database interface functions 
  8. // In this file you'll find some examples of Database command 
  9. // classes:
  10. //        CDbCommit        : implements a database commit command
  11. //        CDbRollback        : implements a database rollback command
  12. //        CDbFindPerson  : implements a search person command
  13. // 
  14. // You can construct your own database classes in a similar way
  15. // =================================================================
  16. #include <stdio.h>
  17. #include <iostream.h>
  18.  
  19. #include "database.h"
  20. ////////////////////////////////////////////////////////////////////
  21. // CDbCommit::CDbCommit
  22. ////////////////////////////////////////////////////////////////////
  23. // Constructor
  24. ////////////////////////////////////////////////////////////////////
  25. CDbCommit::CDbCommit(CDbase &dbase, boolean bUnlock)
  26.     : CDbCommand(dbase)
  27. {
  28.     m_bUnlock = bUnlock;
  29. }
  30.  
  31. ////////////////////////////////////////////////////////////////////
  32. // CDbCommit::~CDbCommit
  33. ////////////////////////////////////////////////////////////////////
  34. // Destructor
  35. ////////////////////////////////////////////////////////////////////
  36. CDbCommit::~CDbCommit()
  37. {
  38. }
  39.  
  40. ////////////////////////////////////////////////////////////////////
  41. // CDbCommit::Do
  42. ////////////////////////////////////////////////////////////////////
  43. // Perform Command
  44. ////////////////////////////////////////////////////////////////////
  45. void CDbCommit::Do()
  46. {
  47.     if (Dbase()->Do(*this))
  48.         ThrowDbError(m_bUnlock);
  49. }
  50.  
  51. ////////////////////////////////////////////////////////////////////
  52. // CDbCommit::Execute
  53. ////////////////////////////////////////////////////////////////////
  54. // Here the call to the Oracel database function is made
  55. // DB_Commit is defined in Oracle.cpp which is the compiled
  56. // Oracle ProC/C++ file where the real database command is 
  57. // exucuted
  58. ////////////////////////////////////////////////////////////////////
  59. long CDbCommit::Execute()
  60. {
  61.     return DB_Commit(this);
  62. }
  63.  
  64. ////////////////////////////////////////////////////////////////////
  65. // CDbRollback::CDbRollback
  66. ////////////////////////////////////////////////////////////////////
  67. CDbRollback::CDbRollback(CDbase &dbase, boolean bUnlock)
  68.     : CDbCommand(dbase)
  69. {
  70.     m_bUnlock = bUnlock;
  71. }
  72.  
  73. ////////////////////////////////////////////////////////////////////
  74. // CDbRollback::~CDbRollback
  75. ////////////////////////////////////////////////////////////////////
  76. CDbRollback::~CDbRollback()
  77. {
  78. }
  79.  
  80. ////////////////////////////////////////////////////////////////////
  81. // CDbRollback::Do
  82. ////////////////////////////////////////////////////////////////////
  83. void CDbRollback::Do()
  84. {
  85.     if (Dbase()->Do(*this))
  86.         ThrowDbError(m_bUnlock);
  87. }
  88.  
  89. ////////////////////////////////////////////////////////////////////
  90. // CDbRollback::Execute
  91. ////////////////////////////////////////////////////////////////////
  92. long CDbRollback::Execute()
  93. {
  94.     return DB_Rollback(this);
  95. }
  96.  
  97. ////////////////////////////////////////////////////////////////////
  98. // CDbConnect::CDbConnect
  99. ////////////////////////////////////////////////////////////////////
  100. CDbConnect::CDbConnect(CDbase &dbase, char* pszConnect)
  101.     : CDbCommand(dbase),
  102.     m_pszConnect(pszConnect)
  103. {
  104. }
  105.  
  106. ////////////////////////////////////////////////////////////////////
  107. // CDbConnect::~CDbConnect
  108. ////////////////////////////////////////////////////////////////////
  109. // Destructor
  110. ////////////////////////////////////////////////////////////////////
  111. CDbConnect::~CDbConnect()
  112. {
  113. }
  114.  
  115. ////////////////////////////////////////////////////////////////////
  116. // CDbConnect::Do
  117. ////////////////////////////////////////////////////////////////////
  118. // Perform Command
  119. ////////////////////////////////////////////////////////////////////
  120. void CDbConnect::Do()
  121. {
  122.     if (Dbase()->Do(*this))
  123.         ThrowDbError(FALSE);
  124. }
  125.  
  126. ////////////////////////////////////////////////////////////////////
  127. // CDbConnect::Execute
  128. ////////////////////////////////////////////////////////////////////
  129. // Here the call to the Oracel database function is made
  130. // DB_Commit is defined in Oracle.cpp which is the compiled
  131. // Oracle ProC/C++ file where the real database command is 
  132. // exucuted
  133. ////////////////////////////////////////////////////////////////////
  134. long CDbConnect::Execute()
  135. {
  136.     return DB_Connect(m_pszConnect);
  137. }
  138.  
  139. ////////////////////////////////////////////////////////////////////
  140. // CDbDisConnect::CDbDisConnect
  141. ////////////////////////////////////////////////////////////////////
  142. CDbDisConnect::CDbDisConnect(CDbase &dbase)
  143.     : CDbCommand(dbase)
  144. {
  145. }
  146.  
  147. ////////////////////////////////////////////////////////////////////
  148. // CDbDisConnect::~CDbDisConnect
  149. ////////////////////////////////////////////////////////////////////
  150. CDbDisConnect::~CDbDisConnect()
  151. {
  152. }
  153.  
  154. ////////////////////////////////////////////////////////////////////
  155. // CDbDisConnect::Do
  156. ////////////////////////////////////////////////////////////////////
  157. // Perform Command
  158. ////////////////////////////////////////////////////////////////////
  159. void CDbDisConnect::Do()
  160. {
  161.     if (Dbase()->Do(*this))
  162.         ThrowDbError(FALSE);
  163. }
  164.  
  165. ////////////////////////////////////////////////////////////////////
  166. // CDbDisConnect::Execute
  167. ////////////////////////////////////////////////////////////////////
  168. // Here the call to the Oracel database function is made
  169. // DB_Commit is defined in Oracle.cpp which is the compiled
  170. // Oracle ProC/C++ file where the real database command is 
  171. // exucuted
  172. ////////////////////////////////////////////////////////////////////
  173. long CDbDisConnect::Execute()
  174. {
  175.     return DB_Disconnect();
  176. }
  177.  
  178.  
  179. ////////////////////////////////////////////////////////////////////
  180. // CDbFindPerson::CDbFindPerson
  181. ////////////////////////////////////////////////////////////////////
  182. CDbFindPerson::CDbFindPerson(char *pszFirstName, char *pszLastName)
  183.     :    CDbCommand()
  184.     ,    m_pszFirstName(pszFirstName)
  185.     ,    m_pszLastName(pszLastName)
  186. {
  187. }
  188.  
  189. ////////////////////////////////////////////////////////////////////
  190. // CDbFindPerson::~CDbFindPerson
  191. ////////////////////////////////////////////////////////////////////
  192. CDbFindPerson::~CDbFindPerson()
  193. {
  194. }
  195.  
  196. ////////////////////////////////////////////////////////////////////
  197. // CDbFindPerson::Do
  198. ////////////////////////////////////////////////////////////////////
  199. void CDbFindPerson::Do()
  200. {
  201.     if (Dbase()->Do(*this))
  202.         ThrowDbError(m_bUnlock);
  203. }
  204.  
  205. ////////////////////////////////////////////////////////////////////
  206. // CDbFindPerson::Execute
  207. ////////////////////////////////////////////////////////////////////
  208. long CDbFindPerson::Execute()
  209. {
  210.     return DB_FindPerson(this, m_pszFirstName, m_pszLastName );
  211. }
  212.  
  213.